package com.toxictest.testproject.core;

import static playn.core.PlayN.*;
import playn.core.GroupLayer;

public abstract class AbstractShape {

	protected GroupLayer layer;
	protected float[] location = { graphics().width() / 2f , 0 };
	protected float angle;
	protected float height;
	protected float width;

	protected static float SPEED_OF_FALL = 3;

	protected static float SPEED_OF_MOTION = 15;

	public void update() {
		location[1] += SPEED_OF_FALL;
		if (location[1] < (graphics().height() - getHeight() / 2))
			layer.setTranslation(location[0], location[1]);
		else
			layer.setTranslation(location[0],
					(graphics().height() - getHeight() / 2));
	}

	public void rotate() {
		angle += java.lang.Math.PI / 2f;
		layer.setRotation(angle);
	}

	public float getHeight() {
		return height;
	}

	public void setHeight(float height) {
		this.height = height;
	}

	public float getLocationX() {
		return location[0];
	}

	public float getLocationY() {
		return location[1];
	}

	public float getWidth() {
		return width;
	}

	public void setWidth(float width) {
		this.width = width;
	}

	public void moveLeft() {

		location[0] -= SPEED_OF_MOTION;
		layer.setTranslation(location[0], location[1]);

	}

	public void moveRight() {

		location[0] += SPEED_OF_MOTION;
		layer.setTranslation(location[0], location[1]);

	}

	public boolean isShape(float x, float y) {

		float leftSide = getLocationX() - getWidth() / 2;
		float rightSide = getLocationX() + getWidth() / 2;
		float topSide = getLocationY() - getHeight() / 2;
		float bottomSide = getLocationY() + getHeight() / 2;

		if ((x > leftSide) && (x < rightSide) && (y > topSide)
				&& (y < bottomSide))
			return true;
		else
			return false;
	}
	
	abstract float[][] getBottomLine() ;
	
	abstract float[][] getTopLine() ;

}
